package com.example.auth;

import io.vertx.core.Vertx;
import io.vertx.ext.auth.jwt.JWTAuth;
import io.vertx.ext.auth.jwt.JWTAuthOptions;
import io.vertx.ext.auth.JWTOptions;
import io.vertx.core.json.JsonObject;

public class JwtProvider {
    private final JWTAuth jwtAuth;

    public JwtProvider(Vertx vertx) {
        JsonObject config = new JsonObject()
            .put("keyStore", new JsonObject()
                .put("type", "jceks")
                .put("path", "keystore.jceks")
                .put("password", "secret"));
        this.jwtAuth = JWTAuth.create(vertx, new JWTAuthOptions(config));
    }

    public String generateToken(String username) {
        return jwtAuth.generateToken(new JsonObject().put("username", username), new JWTOptions().setExpiresInMinutes(60));
    }

    public JWTAuth getProvider() {
        return jwtAuth;
    }
}